package com.axend.sofa.adapter

import android.content.ClipData
import android.content.ClipboardManager
import com.axend.lib_base.engine.toast.toast
import com.axend.lib_base.ext.longClick
import com.axend.lib_room.entity.SofaLogEntity
import com.axend.sofa.R
import com.axend.sofa.databinding.AdapterBleLogItemBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import dagger.hilt.android.scopes.ActivityScoped
import javax.inject.Inject
@ActivityScoped
class BleLogAdapter @Inject constructor() :
    BaseQuickAdapter<SofaLogEntity, BaseDataBindingHolder<AdapterBleLogItemBinding>>(R.layout.adapter_ble_log_item) {
    override fun convert(
        holder: BaseDataBindingHolder<AdapterBleLogItemBinding>,
        item: SofaLogEntity
    ) {
        holder?.dataBinding?.apply {
            tvDate.text = item.date
            tvLogContent.text = item.content
            llContent.longClick {
                /*长按复制*/
                val clipboard =
                    context.getSystemService(android.content.Context.CLIPBOARD_SERVICE) as ClipboardManager
                val clip = ClipData.newPlainText("log", item.content)
                clipboard.setPrimaryClip(clip)
                toast(context.getString(com.axend.lib_base.R.string.app_tips_copy_success))
                true
            }
        }
    }
}